package com.evil.mi.controller;

import com.evil.mi.bean.VideoImgBean;
import com.evil.mi.entity.VideoImgEntity;
import com.evil.mi.service.VideoImgService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * com.evil.mi.controller
 *
 * @author 白雨浓
 * date: 2018/8/23 15:21
 * content:
 */
@RestController
public class VideoImgController {

    @Autowired
    private VideoImgService videoImgService;

    @GetMapping("/img/{videoId}")
    public List<VideoImgBean> getVideoImgList(@PathVariable int videoId) {

        List<VideoImgEntity> entityList = videoImgService.findVideoImgListByVideoId(videoId);

        return entityList.stream().map(entity -> {
            VideoImgBean bean = new VideoImgBean();
            BeanUtils.copyProperties(entity, bean);
            bean.setState(entity.getState().getCode());
            return bean;
        }).collect(Collectors.toList());
    }


}
